angular.module('PackingStorage')

.factory('PackingStorageHomeService', ['$q', 'Http',
    function($q, Http) {
        
        //通过镭射标条码信息获取到信息
        function getItemBarcodeData(code) {
            var deferred = $q.defer();
            Http.post({
                url: "/api/PackingStorage/getAssemblyBarcodeData",
                data: {
                    Parameter: {
                      Barcode: code
                    }
                }
            }).then(function(data) {
                deferred.resolve(data);
            }, function(err) {
                deferred.reject(err);
            });
            return deferred.promise;
        }

        //提交  
        //包装条码，球拍条码主档数组
        function submitData(wareHouseId,packBarcode,barcodeMasters,itemMasterId,deviceId,deviceName,workId,workName,WorkLocationId,WorkLocationName,userId) {
            var deferred = $q.defer();
            Http.post({
                url: "/api/PackingStorage/doStocking",
                data: {
                    Parameter: {
                      wareHouseId:wareHouseId,
                      Packagecode: packBarcode,
                      barcodeMasters: barcodeMasters,
                      ItemMaster: itemMasterId,
                      Terminal: deviceId,
                      TerminalName: deviceName,
                      Work: workId,
                      WorkName: workName,
                      WorkLocation: WorkLocationId,
                      WorkLocationName: WorkLocationName,
                      UserID: userId

                    }
                }
            }).then(function(data) {
                deferred.resolve(data);
            }, function(err) {
                deferred.reject(err);
            });
            return deferred.promise;
        }

        //查找到所有仓库
        function getAllWareHouse(){
            var defer = $q.defer();
            Http.post({
                url: "/api/Kanban/getAllWareHouse",
                data: {
                    Parameter: {
                        
                    }
                }
            }).then(function (data) {
                defer.resolve(data); 
            }, function (err) {
                defer.reject(err);
            });

            return defer.promise;
        }
   
        return {
            getItemBarcodeData: getItemBarcodeData,
            submitData: submitData,
            getAllWareHouse: getAllWareHouse
            
        };
    }
]);